package top.psjj.news.service.impl;

import top.psjj.news.dao.CommentDao;
import top.psjj.news.dao.NewsDao;
import top.psjj.news.po.TComment;
import top.psjj.news.po.TNews;
import top.psjj.news.service.CommentService;

import java.util.List;

/**
 * @Auther:小陈的Java
 */
public class CommentServiceImpl implements CommentService {
    private CommentDao commentDao = new CommentDao();
    private NewsDao newsDao = new NewsDao();
    @Override
    public List<TComment> list(String s_bCommentDate, String s_aCommentDate) throws Exception {
        List<TComment> list = commentDao.list(s_bCommentDate, s_aCommentDate);
        for (TComment comment : list){
            Integer newsId = comment.getNewsId();
            TNews news = newsDao.queryNewsById(newsId);
            comment.setNews(news);
        }
        return list;
    }

    @Override
    public List<TComment> page(String s_bCommentDate, String s_aCommentDate, int begin, int pageSize) throws Exception {
        List<TComment> list = commentDao.page(s_bCommentDate, s_aCommentDate,begin,pageSize);
        for (TComment comment : list){
            Integer newsId = comment.getNewsId();
            TNews news = newsDao.queryNewsById(newsId);
            comment.setNews(news);
        }
        return list;
    }

    @Override
    public int count(String s_bCommentDate, String s_aCommentDate) throws Exception {
        return commentDao.count(s_bCommentDate,s_aCommentDate);
    }
}

